package com.gzk.system.controller;


import com.gzk.basic.util.AjaxResult;
import com.gzk.basic.util.PageList;
import com.gzk.system.domain.WebLog;
import com.gzk.system.query.WebLogQuery;
import com.gzk.system.service.IWebLogService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/weblog")
@Api(tags = "员工接口",description = "员工接口详细描述")
public class WebLogController {

    //注入
    @Autowired
    private IWebLogService webLogService;

    @GetMapping("/{id}")
    public WebLog getById(@PathVariable("id") Long id){
        return webLogService.queryById(id);
    }

    @GetMapping("/list")
    public List<WebLog> getAll(){
        return webLogService.queryAll();
    }

    @PostMapping("/page")
    public PageList<WebLog> pageQuery(@RequestBody WebLogQuery query){
        return webLogService.queryPage(query);
    }

    @DeleteMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            webLogService.remove(id);
            return AjaxResult.ok();
        } catch (Exception e) {
            e.printStackTrace();
            //失败
            return AjaxResult.ok().setSuccess(false).setMessage("系统繁忙！！");
        }
    }

    @PatchMapping("/batch")
    public AjaxResult deleteMany(@RequestBody List<Long> ids){
        try {
            webLogService.removeMany(ids);
            return AjaxResult.ok();
        } catch (Exception e) {
            e.printStackTrace();
            //失败
            return AjaxResult.ok().setSuccess(false).setMessage("系统繁忙！！");
        }
    }


}
